#include<stdio.h>
#include<algorithm>
using namespace std;
typedef struct student
{
	char name[15];
	int num;
}stu[1000];
bool cmp1(student a,student b)
{
	return a.num<b.num;
}

int show(stu *ps)
{
	for(int i=0;i<4;i++)
		printf("%s%d\n",ps[i].name,ps[i].num);
}
int  main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for( int i=0 ; i<n ; i++ )
		scanf("%s%d",stu[i].name,stu[i].v);
	sort(s,s+4,cmp1);
	show(s);
	sort(s,s+4,cmp2);
	show(s);
	return 0;
}
